﻿Imports System.Configuration
Imports BoxOffice.Core.Enumeration

Namespace Configuration

    Public Class FieldElement
        Inherits ConfigurationElement

        '<Field Name="Subject" Type="Select-One" IsRequired="true">

        <ConfigurationProperty("Name", IsKey:=True, IsRequired:=True)> _
        Public Property Name() As String
            Get
                Return DirectCast(Me("Name"), String)
            End Get
            Set(ByVal value As String)
                Me("Name") = value
            End Set
        End Property

        <ConfigurationProperty("Type", DefaultValue:=FormFieldType.TextField, IsRequired:=True)> _
        Public Property Type() As FormFieldType
            Get
                Return DirectCast(Me("Type"), FormFieldType)
            End Get
            Set(ByVal value As FormFieldType)
                Me("Type") = value
            End Set
        End Property

        <ConfigurationProperty("IsRequired", DefaultValue:="false", IsRequired:=False)> _
        Public Property IsRequired() As Boolean
            Get
                Return DirectCast(Me("IsRequired"), Boolean)
            End Get
            Set(ByVal value As Boolean)
                Me("IsRequired") = value
            End Set
        End Property

        <ConfigurationProperty("Answers")> _
        Public ReadOnly Property Answers() As AnswerCollection
            Get
                Return DirectCast(Me("Answers"), AnswerCollection)
            End Get
        End Property

    End Class

    <ConfigurationCollection(GetType(FieldElement))> _
    Public Class FieldCollection
        Inherits ConfigurationElementCollection
        Protected Overloads Overrides Function CreateNewElement() As ConfigurationElement
            Return New FieldElement()
        End Function

        Protected Overloads Overrides Function GetElementKey(ByVal element As ConfigurationElement) As Object
            Return DirectCast((element), FieldElement).Name
        End Function

        Default Public Shadows ReadOnly Property Item(ByVal idx As Integer) As FieldElement
            Get
                Return DirectCast(BaseGet(idx), FieldElement)
            End Get
        End Property
    End Class

End Namespace
